/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-26
 * Time: 21:24
 */
class Solution17 {
    public int jump(int[] nums) {
        int left = 0,right = 0, n = nums.length,maxpos = 0,ret = 0;

        while(left <= right) {
            if(maxpos >= n-1) {
                return ret;
            }
            for(int i = left; i <= right; i++) {
                maxpos = Math.max(maxpos,nums[i]+i);
            }
            left = right+1;
            right = maxpos;
            ret++;
        }
        return -1;
    }
}
